package org.eclipse.gittab.fretboard.internal;

import org.eclipse.gittab.fretboard.FretboardDesign;
import org.eclipse.gittab.fretboard.Fretboard.Configuration;
import org.eclipse.gittab.fretboard.FretboardDesign.FretHeight;
import org.eclipse.swt.graphics.Color;

public interface IFretboardPainter {

	public static final String CONFIG_INVALID = "The fretboard cannot be drawn because the configuration is not valid!";

	/**
	 * Painting routine for drawing a fretboard from left to right.
	 * 
	 * @param ctx
	 */
	public void paint(PaintContext ctx);

	/**
	 * Painting route if configuration is invalid.
	 * 
	 * @param ctx
	 */
	public void paintConfigurationInvalid(PaintContext ctx);

	/**
	 * Removes all allocated resources.
	 */
	public void clean();

	/**
	 * Select a tone on the fretbaord and mark it with a color.
	 * 
	 * @param fret
	 *            fret number starting from 1
	 * @param string
	 *            string number starting from 1 (lowest string)
	 * @param color
	 */
	public void select(int fret, int string, Color color);

	/**
	 * Deselect a selected tone.
	 * 
	 * @param fret
	 * @param string
	 */
	public void deSelect(int fret, int string);

	/**
	 * Gets the color of the selected tone.
	 * 
	 * @param fret
	 * @param string
	 * @return <code>null</code> if not selection available
	 */
	public Color getSelection(int fret, int string);

	/**
	 * Context class for storing information that are needed by the various
	 * painting methods.
	 * 
	 * @author mtreitle
	 * 
	 */
	static class PaintContext {

		private final Configuration config;

		private final FretboardDesign design;

		public PaintContext(final FretboardDesign design,
				final Configuration config) {
			this.design = design;
			this.config = config;
		}

		public FretboardDesign getDesign() {
			return design;
		}

		public Configuration getConfiguration() {
			return config;
		}

		/**
		 * Utility class for getting configuration details from a
		 * {@link PaintContext}.
		 * 
		 * @author mtreitle
		 * 
		 */
		public static class Util {

			public static int nrOfFrets(PaintContext ctx) {
				return ctx.getConfiguration().getFretsNr();
			}

			public static int nrOfStrings(PaintContext ctx) {
				return ctx.getConfiguration().getStringsNr();
			}

			public static FretHeight fretHeight(PaintContext ctx) {
				return ctx.getDesign().fretHeight();
			}
		}
	}

}
